// eslint-disable-next-line @typescript-eslint/no-var-requires
const {readonly, deprecate} = require('core-decorators')

// eslint-disable-next-line @typescript-eslint/no-namespace
namespace d {
  //本身pi: number = 3.12 这样定义是实例上的属性 但经过@readonly是定义在原型上的
  function ireadonly(target: any, key: any) {
    Object.defineProperty(target, key, {
      writable: false
    })
  }

  function ideprecate(target: any, methodName: any, descriptor: any) {
    const oldVal = descriptor.value//先缓存老的函数
    //@ts-ignore
    descriptor.value = function (...args) {
      const message = (
        `DEPRECATION ${target.constructor.name}#${methodName}: This function will be removed in future versions.`
      )
      console.warn(message)
      return oldVal(...args)
    }
  }

  class Circle {
    // @readonly
    pi: number = 3.12
    @deprecate
    getName(){
      console.log('getName')
    }
  }
  const circle = new Circle()
  circle.pi
  circle.pi = 3.16
  console.log(circle.pi)
  //02.ts:19 Uncaught TypeError: Cannot assign to read only property 'pi' of object '#<Circle>'


  circle.getName()
  //DEPRECATION Circle#getName: This function will be removed in future versions.
}
